<template>
	<view class="page-container">
		<view class="padded-15">
			<uni-forms ref="form" :rules="rules" :modelValue="formData">
				<view class="font-16 padded-5">基本信息</view>
				<view class="form-container margin-t-5">
					<view class="border-b-F5F5F5 form-item-view">
						<uni-forms-item label="月均收入" label-width="80" name="m_income">
							<uni-easyinput type=number v-model="formData.m_income" :maxlength="8" :inputBorder="false" placeholder="（元）" />
						</uni-forms-item>
					</view>
					<view class="border-b-F5F5F5 form-item-view">
						<uni-forms-item label="房产价值" label-width="80" name="house_value">
							<uni-easyinput type=number v-model="formData.house_value" :inputBorder="false" placeholder="（万元）" />
						</uni-forms-item>
					</view>
					<view class="border-b-F5F5F5 form-item-view">
						<uni-forms-item label="其他资产价值" label-width="80" name="other_value">
							<uni-easyinput type=number v-model="formData.other_value" :inputBorder="false" placeholder="（万元）" />
						</uni-forms-item>
					</view>
					<view class="border-b-F5F5F5 form-item-view">
						<uni-forms-item label="储蓄额" label-width="80" name="deposit">
							<uni-easyinput type=number v-model="formData.deposit" :inputBorder="false" placeholder="（万元）" />
						</uni-forms-item>
					</view>
				</view>
				
				<view class="padded-60"></view>
				<view class="page-bottom clearfix">
					<view class="cancle-btn pull-left">
						<button type="default" class="font-14 bg-FFFFFF padded-t-10 padded-b-10" :data-url="'/pages/index/data_upload'" @click="clickJump">取消</button>
					</view>
					<view class="save-btn pull-left padded-l-10">
						<button type="primary" class="font-14 padded-t-10 padded-b-10"  @click="submit">保存</button>
					</view>
				</view>
				
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(options) {
			
			this.getServerData();
		},
		data() {
			return {
				formData: {
					m_income: '',
					house_value: '',
					other_value: '',
					deposit: ''
				},
				rules: {},
			}
		},
		onReady() {
		
		},
		methods: {
			getServerData() {
				this.$request().then(res => {
					// 验证登入
				})
				
				// 使用 GET 方法请求数据
				uni.request({
				    url: 'https://wn.wdyky.com/index/jrgl/jczl', // 请求地址
				    success: (res) => {
				        // 请求成功的回调函数
				        console.log('请求成功:', res.data);
						if(res.data.code == 1){
							this.formData = res.data.data;
						}
				    },
				    fail: function(err) {
				        // 请求失败的回调函数
				        console.error('请求失败:', err);
				    }
				});
			},
			submit(){
				uni.request({
				    url: 'https://wn.wdyky.com/index/jrgl/jczlsave', // 你的API接口地址
				    method: 'GET',
				    data: {
						data: this.formData
				    },
				    success: (res) => {
						
						if(res.data.code != 1){
							
							uni.showToast({
								icon: 'none',
								title: res.data.val
							})
						}
						if(res.data.code == 1){
							uni.showToast({
								icon: 'none',
								title: res.data.val
							});
							uni.navigateBack();
						}
						//console.log('请求成功:', res.data);
				    },
				    fail: (err) => {
				        console.error('GET请求失败：', err);
				    }
				});
			},
			// 跳转
			clickJump(e){
				uni.navigateBack();
			},
		},
	}
</script>

<style lang="scss">
	@import '@/static/product.scss';
	
	.form-container {
		background: #FFFFFF;
		border-radius: 10px;
		box-shadow: 0 0 3px 3px rgba(242, 242, 242, 0.7);
		
		.form-item-view {
			padding: 15px 10px;
			
			.uni-forms-item {
				margin: 0;
				padding: 0 10px;
				
				.uni-easyinput__placeholder-class {
					text-align: right;
					color: #646D7F;
					font-size: 14px;
				}
				
				::v-deep .uni-input-input {
					text-align: right;
				}
				
				::v-deep .input-value-border {
					border: none;
					padding-right: 0;
				}
			}
		}
	}
	
	.page-bottom {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 15px;
		padding-bottom: 30px;
		background: #FAFAFA;
		
		.cancle-btn {
			width: 90px;
			
			uni-button {
				box-shadow: 0 0 3px 3px rgba(242, 242, 242, 0.7);
			}
			
			uni-button:after {
				border: 0;
			}
			
		}
		
		.save-btn {
			width: calc(100% - 90px);
			
			uni-button {
				box-shadow: 0 0 3px 3px rgba(242, 242, 242, 0.7);
			}
			
			uni-button:after {
				border: 0;
			}
			
		}
	}
	
</style>
